﻿using System;
using System.Diagnostics;
using My.Ioc;

namespace LazyRegistration
{
    public interface ILazyType 
    { }
    public class LazyType : ILazyType  
    { }

    class Program
    {
        static bool _eventHandled = false;

        static void Main(string[] args)
        {
            IObjectContainer container = new ObjectContainer(false);
            container.ObjectBuilderRequested += OnObjectBuilderRequested;
            var lazy = container.Resolve<ILazyType>();
            Debug.Assert(lazy != null);
            Debug.Assert(lazy is LazyType);

            Console.WriteLine(_eventHandled);
            Console.ReadLine();
        }

        static void OnObjectBuilderRequested(ObjectBuilderRequestedEventArgs args)
        {
            if (args.ContractType == typeof (ILazyType))
            {
                args.Register<ILazyType, LazyType>();
                _eventHandled = true;
            }
        }
    }
}
